#导入pymysql 
import pymysql
from pymysql import cursors

#封装
class DB:
    def __init__(self):
        self.conn = pymysql.connect(host='localhost',port=3306,user='root',password='123',charset='utf8',db='shop',cursorclass = pymysql.cursors.DictCursor)
        self.cursor = self.conn.cursor()
    
    #添加,修改,删除
    def insert(self,sql):
        self.cursor.execute(sql)
        self.conn.commit()
    
    #查询一条记录
    def find(self,sql):
        self.cursor.execute(sql)
        return self.cursor.fetchone()
    
    #查询多条记录
    def findall(self,sql):
        self.cursor.execute(sql)
        return self.cursor.fetchall()


db1 = DB()        